package cn.kawa.basic.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
@Component
public class EmailUtils {

    @Autowired
    private JavaMailSender javaMailSender;

    public  void send2() throws MessagingException {
        //创建复杂邮件对象
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        //发送复杂邮件的工具类
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
        helper.setFrom("1309968964@qq.com");
        helper.setSubject("店铺激活邮件");
        helper.setText("<h1>你的店铺已经注册!!!</h1><img src='http://123.207.27.208/group1/M00/00/FF/CgAIC2LeEYiAc171AADByvUlnxc097.jpg' ><a href='http://localhost:8080/shop/active/22'>点击该链接激活</a>",true);
        //添加附件
        helper.addAttachment("p77.jpg",new File("C:\\Users\\admin\\Desktop\\desk_IOfile\\2222.jpg"));
        //收件人
        helper.setTo("1309968964@qq.com");
        javaMailSender.send(mimeMessage);
    }
}
